package com.wholeintech.dao;

import com.wholeintech.utils.CommonUtil;
import com.wholeintech.entity.DeviceDb;

import org.xutils.DbManager;

import java.util.ArrayList;
import java.util.List;

/**
 * 设备实体数据库操作类
 */
public class DeviceDao {
    private DeviceDao(){

    }

    private static class SingletonInstance{
        private final static DeviceDao instance = new DeviceDao();
    }

    public static DeviceDao getInstance(){
        return SingletonInstance.instance;
    }

    /**
     * 获取指定网关的子设备
     * @param strGwDevId
     * @return
     */
    public List<DeviceDb> getSubDevices(String strGwDevId){
        List<DeviceDb> subDevices = new ArrayList<>();
        DbManager db = CommonUtil.MyDbUtils();
        try {
            subDevices = db.selector(DeviceDb.class).where("gwDevId", "=", strGwDevId).findAll();
        }catch (Exception ex){
            ex.printStackTrace();
        }

        return subDevices;
    }

    /**
     * 获取指定devId的设备
     * @param strDevId
     * @return
     */
    public DeviceDb getDeviceDb(String strDevId){
        DeviceDb deviceDb = null;
        DbManager db = CommonUtil.MyDbUtils();
        try {
            deviceDb = db.selector(DeviceDb.class).where("devId", "=", strDevId).findFirst();
        }catch (Exception ex){
            ex.printStackTrace();
        }

        return deviceDb;
    }
}
